package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.AdminMapper;
import com.xxxx.server.mapper.AdminRoleMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.AdminRole;
import com.xxxx.server.service.IAdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements IAdminRoleService {

    @Autowired
    private AdminRoleMapper adminRoleMapper;
    @Autowired
    private AdminMapper adminMapper;

    @Transactional
    @Override
    public void updateByAid(int adminId, Integer[] ids) {
        Assert.isTrue(adminId > 0,"错误");
        Admin admin = adminMapper.selectById(adminId);
        Assert.notNull(admin,"该记录不存在");
        this.remove(new QueryWrapper<AdminRole>().eq("adminId",adminId));
        adminRoleMapper.updateRoleId(adminId,ids);
    }

    @Transactional
    @Override
    public void removeRole(int id) {
        adminMapper.deleteById(id);
        adminRoleMapper.delete(new QueryWrapper<AdminRole>().eq("adminId",id));
    }
}
